package com.ztgf.order.api.cms;

import com.baomidou.mybatisplus.plugins.Page;
import com.ztgf.common.constant.Result;
import com.ztgf.common.enums.CodeEnum;
import com.ztgf.order.models.bo.OrderReturnCommodityAdminBO;
import com.ztgf.order.models.bo.OrderReturnCommodityUpdateBO;
import com.ztgf.order.models.service.IOrderReturnCommodityService;
import com.ztgf.order.models.vo.OrderReturnCommodityAdminListVO;
import com.ztgf.order.models.vo.OrderReturnCommodityDetailsVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * author: chenyu.wang
 * date: 2020-06-30 15:57
 * Description:
 */
@RestController
@RequestMapping("/cms/orderReturnCommodity")
@Slf4j
@Api(value = "OrderReturnCommodityController", tags = "订单退换货表接口")
public class OrderReturnCommodityController {

    @DubboReference
    private IOrderReturnCommodityService iOrderReturnCommodityService;

    @PostMapping(value = "/updateInterventionDeal")
    @ApiOperation(value = "平台处理接口", notes = "平台处理接口")
    public Result updateInterventionDeal(OrderReturnCommodityUpdateBO updateBO) {
        if (null != updateBO.getId()) {
            return iOrderReturnCommodityService.updateInterventionDeal(updateBO);
        } else {
            return new Result<>(CodeEnum.FAIL_100002);
        }
    }

    @PostMapping(value = "/getDetailsById")
    @ApiOperation(value = "查询售后订单详情", notes = "查询售后订单详情")
    public Result getDetailsById(Long id) {
        if (null != id) {
            OrderReturnCommodityDetailsVO details = iOrderReturnCommodityService.getDetailsById(id);
            return new Result<>(details);
        } else {
            return new Result<>(CodeEnum.FAIL_100002);
        }
    }


    @PostMapping(value = "/queryAdminPageList")
    @ApiOperation(value = "个人中心我的售后列表接口", notes = "个人中心我的售后列表接口")
    public Result queryAdminPageList(OrderReturnCommodityAdminBO bo) {
        Page<OrderReturnCommodityAdminListVO> pageList = iOrderReturnCommodityService.queryAdminPageList(bo);
        return new Result<>(pageList);
    }


    @PostMapping(value = "/getAfterOrderNumber")
    @ApiOperation(value = "统计售后订单及投诉与建议未处理数量", notes = "统计售后订单及投诉与建议未处理数量")
    public Result getAfterOrderNumber() {
        Integer number = iOrderReturnCommodityService.getAfterOrderNumber();
        return new Result<>(number);
    }

    @PostMapping(value = "/updateConsortState")
    @ApiOperation(value = "平台协调后判定输赢", notes = "平台协调后判定输赢")
    public Result updateConsortState(Long id, Integer state, String context) {
        if (null == id) {
            return new Result<>(CodeEnum.FAIL_100002);
        } else {
            Result<List<String>> result = iOrderReturnCommodityService.updateConsortState(id, state, context);
            return new Result<>(result);
        }
    }
}
